#include <iostream>
#include "arithmetic.h"

int main()
{
	int result = 0;
	int p = 1;
	point a, b, c, d;

	int n, t;
	std :: cin >> n >> t;
	if (t == 1)
	{
		int seed;
		std :: cin >> seed;
		RandomInput in(seed);
		for (int i = 0; i < n; ++i, p *= 239)
		{
			a = point(in), b = point(in),	c = point(in), d = point(in);
			if (is_intersection(a ,b, c, d))
			    result += p;
		}
	}
	else
	{
		for (int i = 0; i < n; ++i, p *= 239)
		{
			std :: cin >> a >> b;
			std :: cin >> c >> d;
			if (is_intersection(a ,b, c, d))
				result += p;
		}
	}
	std::cout << result << "\n";

	return 0;
}
